package cn.oscar.service.imp;

import cn.oscar.mapper.CommentMapper;
import cn.oscar.service.CommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import commonUtils.entities.Comment;
import commonUtils.entities.Restful;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CommentServiceImp extends ServiceImpl<CommentMapper, Comment> implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public Restful<List<Comment>> selectCommentByBlogId(Long id) {
        List<Comment> comments = commentMapper.selectCommentByBlogId(id);
        return Restful.success(comments);
    }

    @Override
    public Restful<String> addComments(Comment comment) {
        comment.setCreateTime(LocalDateTime.now());
        // TODO 设置当前评论的用户id，用户id可以使用上下文获取
        // TODO 设置评论所属用户头像和图片？逻辑是什么
//        comment.setUserId();
        save(comment);
        return Restful.success("添加评论成功");
    }

    @Override
    public Restful<String> deleteComment(Comment comment) {
        removeById(comment.getId());
        return Restful.success("删除评论成功");
    }
}
